{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<CENTER><img src=\"http://opendata.atlas.cern/DataAndTools/pictures/ATLASOD.gif\" style=\"width:50%\"></CENTER>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<CENTER><h1>Get running the analysis of Hyy channel using the 13 TeV dataset in Python</h1></CENTER>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Introduction**\n",
    "Let's take a current ATLAS Open Data sample and create histograms:\n",
    "\n",
    "Import some Python packages"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import time"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Show the start time: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mon Aug 12 18:18:05 CEST 2019\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('date').read()\n",
    "print(myCmd)\n",
    "start = time.time()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. Get Hyy analysis code of 13Tev dataset  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Creat a folder \"python-13tev\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "command1 = 'mkdir python-13tev'\n",
    "os.system(command1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Show the contents in the current folder"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total 72K\n",
      "-rw-r--r-- 1 summerstudent users  125 Jul 22 11:07 README.md\n",
      "-rw------- 1 summerstudent users 9.6K Jul 22 11:26 get-running-8-tev-code-cpp.ipynb\n",
      "-rw-r--r-- 1 summerstudent users  18K Jul 31 20:36 get-running-8-tev-code-python.ipynb\n",
      "drwxr-xr-x 2 summerstudent users 4.0K Jul 31 22:37 images\n",
      "-rw-r--r-- 1 summerstudent users  14K Aug 12 17:38 get-running-13-tev-python-code.ipynb\n",
      "-rw-r--r-- 1 summerstudent users  11K Aug 12 18:17 get-running-13-tev-cpp-code.ipynb\n",
      "drwxr-xr-x 2 summerstudent users 4.0K Aug 12 18:18 python-13tev\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('ls -lhrt').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Print the current path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/student/demos-framework-software-notebooks\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('pwd').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Get into the folder which we just created"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "os.chdir(\"python-13tev/\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Print the current path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/student/demos-framework-software-notebooks/python-13tev\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('pwd').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Clone the analysis code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "command2 = 'git clone https://gitlab.cern.ch/yixin/atlas-outreach-cpp-framework-13tev.git'\n",
    "os.system(command2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Get into the folder which contains the analysis code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "os.chdir(\"atlas-outreach-cpp-framework-13tev/Beta/\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Print the current path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/student/demos-framework-software-notebooks/python-13tev/atlas-outreach-cpp-framework-13tev/Beta\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('pwd').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mon Aug 12 18:18:06 CEST 2019\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('date').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. Download the 13Tev dataset for Hyy analysis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#command3 = 'wget -c http://opendata.atlas.cern/release/samples/2019/GamGam/ATLAS-open-data-13TeV-2019-GamGam.zip'\n",
    "#os.system(command3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#command4 = 'unzip ATLAS-open-data-13TeV-2019-GamGam.zip'\n",
    "#os.system(command4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#command5 = 'rm -rf ATLAS-open-data-13TeV-2019-GamGam.zip'\n",
    "#os.system(command5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#os.chdir(\"..\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. Begin analysis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/student/demos-framework-software-notebooks/python-13tev/atlas-outreach-cpp-framework-13tev/Beta\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('pwd').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Run the welcome script to start"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "command6a = 'mkdir -p Analysis/HyyAnalysis/Output_HyyAnalysis' \n",
    "command6b = 'rm -rf Analysis/HyyAnalysis/Output_HyyAnalysis/*'\n",
    "os.system(command6a + ';' + command6b)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Change to the analysis code path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "os.chdir(\"Analysis/HyyAnalysis/\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/student/demos-framework-software-notebooks/python-13tev/atlas-outreach-cpp-framework-13tev/Beta/Analysis/HyyAnalysis\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('pwd').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total 44K\n",
      "-rwxr-xr-x 1 summerstudent users  347 Aug 12 18:18 run.sh\n",
      "-rwxr-xr-x 1 summerstudent users  271 Aug 12 18:18 run0.sh\n",
      "-rw-r--r-- 1 summerstudent users 1.4K Aug 12 18:18 main_HyyAnalysis.C\n",
      "-rw-r--r-- 1 summerstudent users 1.5K Aug 12 18:18 HyyAnalysisHistograms.h\n",
      "-rw-r--r-- 1 summerstudent users  16K Aug 12 18:18 HyyAnalysis.h\n",
      "-rw-r--r-- 1 summerstudent users 5.9K Aug 12 18:18 HyyAnalysis.C\n",
      "lrwxrwxrwx 1 summerstudent users   11 Aug 12 18:18 clean.sh -> ../clean.sh\n",
      "drwxr-xr-x 2 summerstudent users 4.0K Aug 12 18:18 Output_HyyAnalysis\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('ls -lhrt').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now it's time to RUN!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "command7 = './run0.sh 0'\n",
    "os.system(command7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mon Aug 12 18:22:02 CEST 2019\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('date').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4. Plot the result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "os.chdir(\"../../Plotting_Hyy/\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/student/demos-framework-software-notebooks/python-13tev/atlas-outreach-cpp-framework-13tev/Beta/Plotting_Hyy\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('pwd').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "command8 = './plotting.sh'\n",
    "os.system(command8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total 80K\n",
      "-rw-r--r-- 1 summerstudent users 25K Aug 12 18:18 hist_mYY_pt.png\n",
      "-rw-r--r-- 1 summerstudent users 23K Aug 12 18:22 hist_mYY_incl.png\n",
      "-rw-r--r-- 1 summerstudent users 26K Aug 12 18:22 hist_mYY_win.png\n",
      "\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('ls -lhrt histograms/').read()\n",
    "print(myCmd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Show the end time and the analysis duration"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The following are the plots you drew located in **python-13tev/atlas-outreach-cpp-framework-13tev/Beta/Plotting_Hyy/histograms**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<CENTER><img src=\"python-13tev/atlas-outreach-cpp-framework-13tev/Beta/Plotting_Hyy/histograms/hist_mYY_incl.png\"></CENTER>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mon Aug 12 18:22:12 CEST 2019\n",
      "\n",
      "Finished in 4 min 7 s\n"
     ]
    }
   ],
   "source": [
    "myCmd = os.popen('date').read()\n",
    "print(myCmd)\n",
    "end = time.time()\n",
    "duration = end-start\n",
    "print(\"Finished in {} min {} s\").format(int(duration//60),int(duration%60))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
